package com.tude._07vehicle.base.config;

import com.tude._07vehicle.base.interceptor.LoginCheckInterceptor;
import com.tude._07vehicle.base.interceptor.MyInterceptor;
import com.tude._07vehicle.base.interceptor.RateLimitInterceptor;
import com.tude._07vehicle.base.interceptor.TimeAccessInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/*多拦截器执行顺序源码
    - 第1步：Ctrl + n 搜索 DispatcherServlet；
    - 第2步：点击Idea工具栏左侧 structure；
    - 第3步：找到 doDispatch 方法；
    - 第4步：查看 applyPreHandle 源码，查看执行顺序；
    - 第5步：查看 applyPostHandle 源码，查看执行顺序；
    - 第6步：找到 triggerAfterCompletion 源码，继续进入 triggerAfterCompletion ，查看执行顺序.*/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/vehicle/**");

        registry.addInterceptor(new TimeAccessInterceptor())
                .addPathPatterns("/v1/**");

        registry.addInterceptor(new LoginCheckInterceptor())
               .addPathPatterns("/v1/vehicle/**");

        registry.addInterceptor(new RateLimitInterceptor())
                .addPathPatterns("/v1/vehicle/list");
    }
}
